<?php 
/**
 * ... ...
 * ... ...
 *
 */ 


JCAT_Package::ImportClass('JCAT_GtkDialog',JCAT::PACKAGE_MVCGTK) ;
JCAT_Package::ImportInterface('JCAT_IViewForm',JCAT::PACKAGE_MVC) ;


/**
 * 视图类 SQLExpressionDlg 
 *
 * @access public
 */
class SQLExpressionDlg 
	//<<[UnmodifiableBlock.Start]::Extends And Implements::>>//
	extends JCAT_GtkDialog
	implements JCAT_IViewForm
	//<<[UnmodifiableBlock.End]::Extends And Implements::>>// 
{
	
	/**
	 * 构造函数 
	 *
	 * @access	public
	 * @param	$aParent	JCAT_IViewContainer		视图的父对象(父视图 或 控制器)。注意：视图不应单独存在，必须有一个父对象！ 
	 * @return	void
	 */
	public function SQLExpressionDlg(JCAT_IViewContainer $aParent
						,array $arrTables=array()
						, $sLeft = ''
						, $sOperator = '='
						, $sRight = ''
						, $sRightB = '' )
	{
		// 调用父类构造函数 
		//<<[UnmodifiableBlock.Start]::Call Parent Construct::>>//
		$this->JCAT_GtkDialog('SQLExpressionDlg','template.DBConditionView.glade','DlgSQLExpression',$aParent) ;
		//<<[UnmodifiableBlock.End]::Call Parent Construct::>>// 

		$this->Initialize() ;	//HBOxRightB
		
		// 文档
		$aDialogDocument = new JCAT_ArchiveDocument('DBTableLinkDialogDocument') ;
		$aDialogDocument->Set('Left',$sLeft) ;
		$aDialogDocument->Set('Operator',$sOperator) ;
		$aDialogDocument->Set('Right',$sRight) ;
		$aDialogDocument->Set('RightB',$sRightB) ;
		$this->SetDocument($aDialogDocument) ;
		
		// 菜单
		$this->aSideMenu = new GtkMenu() ;
		$aMenuItem = new GtkMenuItem(JCAT_Language::Sentence('网页POST参数')) ;
		$aMenuItem->connect_simple('activate',array($this,'OnConditionMenuItemActivate'),'{$_POST[\'\']}') ;
		$this->aSideMenu->append($aMenuItem);
		$aMenuItem = new GtkMenuItem(JCAT_Language::Sentence('网页GET参数')) ;
		$aMenuItem->connect_simple('activate',array($this,'OnConditionMenuItemActivate'),'{$_GET[\'\']}') ;
		$this->aSideMenu->append($aMenuItem);
		$aMenuItem = new GtkMenuItem(JCAT_Language::Sentence('网页POST或GET参数')) ;
		$aMenuItem->connect_simple('activate',array($this,'OnConditionMenuItemActivate'),'{$_REQUEST[\'\']}') ;
		$this->aSideMenu->append($aMenuItem);

		// 数据表/字段 
		foreach ($arrTables as $sTableName=>$arrColumns)
		{
			// 字段菜单
			$aColumnMenu = new GtkMenu() ;
			
			foreach ($arrColumns as $sColumnName)
			{
				$aColumnItem = new GtkMenuItem($sColumnName) ;
				$aColumnItem->connect_simple('activate',array($this,'OnConditionMenuItemActivate'),"{$sTableName}.{$sColumnName}") ;
				$aColumnMenu->append($aColumnItem);
			}
			
			// 数据表选项
			$aMenuItem = new GtkMenuItem($sTableName) ;
			$aMenuItem->set_submenu($aColumnMenu) ;
			$this->aSideMenu->append($aMenuItem);
		}

	}
	
	
	
	/**
	 * 初始化 视图 
	 *
	 * @access	protected
	 * @return	void
	 */
	protected function Initialize()
	{
		//<<[UnmodifiableBlock.Start]::UICtrl Children::>>//
		// 载入UI控件
		$sCurrentDirectory = dirname(__FILE__).'/' ;
		$this->AddUICtrl(JCAT_Package::ImportInstance($sCurrentDirectory.'Instance.UICtrls/instance.Operator.php'),'Operator') ;
		$this->AddUICtrl(JCAT_Package::ImportInstance($sCurrentDirectory.'Instance.UICtrls/instance.RightB.php'),'RightB') ;
		$this->AddUICtrl(JCAT_Package::ImportInstance($sCurrentDirectory.'Instance.UICtrls/instance.Right.php'),'Right') ;
		$this->AddUICtrl(JCAT_Package::ImportInstance($sCurrentDirectory.'Instance.UICtrls/instance.Left.php'),'Left') ;
		//<<[UnmodifiableBlock.End]::UICtrl Children::>>// 
	
		
		// 在此加入其它初始化代码 
	 	// TODO ... ...
	 	

	}
	
	
	
	/**
	 * 创建主窗体事件 
	 *
	 * @access	protected
	 * @return	void
	 */
	 protected function OnInitView()
	 {
	 	// 数据交换
	 	$this->ExchangeData(JCAT_IViewForm::DOC_TO_UICTRL) ;
	 }

	 
	 /**
	  * what's this
	  * 
	  * @access	public
	  * @param	$sEntryName			what's this
	  * @return	void
	  */
	 public function OnSelectCondition($sEntryName)
	 {
	 	$this->sSetEntryName = $sEntryName ;
	 	
	 	$this->aSideMenu->set_visible(true) ;
	 	$this->aSideMenu->popup() ;
	 	
	 }
	 
	/**
	 * 当 UICtrl 中的数据改变时，触发此事件
	 * 
	 * @access	public
	 * @param 	$aUICtrl	JCAT_IUIGtkCtrl
	 * @return	void
	 */
	public function OnUICtrlChanged( JCAT_IUIGtkCtrl $aUICtrl )
	{
		if( $aUICtrl->GetName()=='Operator' )
		{
			$sValue = $aUICtrl->GetExchangeData() ;
			$bShowRightB = ($sValue=='BETWEEN') ;
			
			$wndHBOxRightB = $this->GetChildWidget('HBOxRightB') ;
			JCAT_ASSERT::ASSERT_INSTANCE($wndHBOxRightB,'GtkHBox') ;			
			$wndHBOxRightB->set_visible($bShowRightB) ;
		}
		
		return parent::OnUICtrlChanged($aUICtrl) ;	
	}

	/**
	 * what's this
	 * 
	 * @access	public
	 * @param	$sValue			string			what's this
	 * @return	void
	 */
	public function OnConditionMenuItemActivate($sValue)
	{
		if(!$this->sSetEntryName)
		{
			return ;
		}
		$wndEntry = $this->GetChildWidget($this->sSetEntryName) ;
		JCAT_ASSERT::ASSERT_INSTANCE($wndEntry,'GtkEntry') ;
		
		$wndEntry->set_text($sValue) ;		
	}
	 
	 /**
	  * what's this
	  * 
	  * @access	public
	  * @return	string
	  */
	 public function GetExpression()
	 {
	 	$sLeft = $this->GetSide('Left') ;
	 	$sRight = $this->GetSide('Right') ;
	 	$sOperator = $this->GetSide('Operator') ;
	 	
	 	$sRet = "{$sLeft} {$sOperator} {$sRight}" ;
	 	
	 	// 三目运算
	 	if($sOperator=='BETWEEN')
	 	{
	 		$sRightB = $this->GetSide('RightB') ;
	 		$sRet.= " AND {$sRightB}" ;
	 	}

	 	return $sRet ;
	 }
	 
	 /**
	  * what's this
	  * 
	  * @access	public
	  * @return	void
	  */
	 public function GetOperator()
	 {
	 	$aDocument = $this->GetDocument() ;
	 	return $aDocument->Get('Operator') ;
	 }
	 
	 
	 /**
	  * what's this
	  * 
	  * @access	public
	  * @return	void
	  */
	 public function GetSide($sSide='Left')
	 {
	 	$aDocument = $this->GetDocument() ;
	 	return $aDocument->Get($sSide) ;
	 }
	 
	 
	/**
	 * 对话框 “确定” 按钮事件函数 
	 * 
	 * @access	public
	 * @return	bool
	 */
	public function OnOK() 
	{
		$aMessageQueue = new JCAT_MessageQueue() ;
		JCAT_MessageDispatcher::RegisterMessageQueue($aMessageQueue,'MSGMVC') ;
		JCAT_MessageDispatcher::RegisterMessageQueue($aMessageQueue,'MSGMVC_OK') ;
		JCAT_MessageDispatcher::RegisterMessageQueue($aMessageQueue,'MSGMVC_BAD') ;
		JCAT_MessageDispatcher::RegisterMessageQueue($aMessageQueue,'MSGMVC_DEBUG') ;

		// 消息输出器
		JCAT_Package::ImportClass('JCAT_MessageGtkDialogPrinter',JCAT::PACKAGE_MSG) ;
		$aMessageQueuePrinter = new JCAT_MessageGtkDialogPrinter($aMessageQueue) ;
		$aMessageQueue->AddPrinter($aMessageQueuePrinter) ;
		
		if( !$this->VerifyData() )
		{
			if( $aMessageQueue->GetMessageCount() )
			{
				$aMessageQueue->PrintQueue() ;
			}
			
			$aMessageQueue->Delete() ;
			return ;
		}
		$aMessageQueue->Delete() ;

		$this->ExchangeData() ;		
		return parent::OnOK() ;
	}
	 
	 
	/**
	 * 
	 * 
	 * @access	private
	 * @var		array
	 */
	private $arrTables = array() ;

	/**
	 * 
	 * 
	 * @access	private
	 * @var		GtkMenu
	 */
	private $aSideMenu ;
	
	/**
	 * 
	 * 
	 * @access	private
	 * @var		string
	 */
	private $sSetEntryName ;
}

?><?
/**
 * [注意!!]
 *	以下内容由 JCAT PHP Toolbox 自动维护，手动更改的内容会被 JCAT PHP Toolbox 抹除，
 *	同时还可能破坏格式，导致 JCAT PHP Toolbox 无法正常读取。
 */
/*<<[UnmodifiableB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